function GetArgsFromHref(sHref, sArgName){
      var args    = sHref.split("?");
      var retval = "";
    
      if(args[0] == sHref) /*参数为空*/
      {
           return retval; /*无需做任何处理*/
      }  
      var str = args[1];
      args = str.split("&");
      for(var i = 0; i < args.length; i ++)
      {
          str = args[i];
          var arg = str.split("=");
          if(arg.length <= 1) continue;
          if(arg[0] == sArgName) retval = arg[1]; 
      }
      return retval;
}

var email = GetArgsFromHref(window.location.href,'email');
$("#email").attr("email",email)

function data_post(_file){
	var post={};
	var expand = {};
	var email = $("#email").attr("email");
	var order_code = $(".active .order_code").attr("name");
	$(".active .post").each(function(){
		var _this =$(this);
		var val = _this.val();
		var _name = _this.attr("name");
		if (_name.indexOf('expand_') >=0){
			_name = _name.replace(/expand_/,'')
			expand[_name] = val
			post['expand'] = expand;
		}else{
			post[_name]=val;
		}

	})
	if(_file !== undefined){
		post.file=_file;
	}
	if (filebox !== undefined){
		post.file=filebox;
	}
	
//	console.log(post)
//	return false;
	$.ajax({
		type:"post",
		url:"./app/index.php?m=index&a=submit",
		data:{'post':post,'order_code':order_code,'email':email},
		success:function(ret){
			alert(ret.info)
		}
	});
}

/**
 * 图片上传后，缩略图显示
 * @param data    返回信息
 * @param thumbclass 目标显示的class
 * @param array   存储路径集合，这个参数有点坑爹，不是我想的，迫不得已而为
 */
function after_upload(data,thumbclass,array){
	//判断是不是图片类型
	var imgType = 'jpg,gif,png,jpeg';
	var html = "";
	for(var i in array){
		if (imgType.indexOf(data.ext) >=0 ){
    		html = "<img class='fl' src='."+array[i]+"'>";
		}else{
			//不是图片类型
			html = "<p>附件["+data.name+"]已上传成功。</p>";
		}
	}

	$(thumbclass).prepend(html);
} 



/**
 * uploaddify上传插件
 */
var filebox = {};
function uploadify(id,ext){
	var setext = '*.mp4;*.mov;*.pdf;*.ppt;*.pptx;*.xlsx;*xls;*.doc;*.mp3;*.docx;*.jpeg;*.tiff;'
	if (ext) setext = ext;
    $(id).uploadify({
        'swf'      : './js/uploadify/uploadify.swf',    //指定上传控件的主体文件
        'uploader' : './app/index.php?m=index&a=upload' ,   //指定服务器端上传处理文件
        'fileTypeExts':setext, //上传文件后缀名
        'buttonText'  : '上传',  //按钮文字
        'method':'post',
        'onUploadComplete':function(){
        },
        'onUploadSuccess': function (fileObj, data, response) {
        	data = JSON.parse(data);
        	var file_element_name = id.substr(1);
        	if (filebox[file_element_name] == undefined) filebox[file_element_name] = [];
        	filebox[file_element_name].push(data.path)
        	var imgType = 'jpg,gif,png,jpeg';
        	var html = "";
        	if (imgType.indexOf(data.ext) >=0 ){
        		html = "<div class='fl thumb_img'>"+
							"<p><img  src='."+data.path+"' width='80px' height='80px' ></p>"+
							"<a href='javascript:;' onClick='thumb_del(this)' class='thumb_del'>删除</a>"+
						"</div>";
        	}else{
        		//不是图片类型
        		html = "<div class='fl thumb_img'>"+
    						"<p>附件["+data.name+"]</p>"+
							"<a href='javascript:;' onClick='thumb_del(this)' class='thumb_del'>删除</a>"+
						"</div>";
        		
        	}
        	$(id+'_thumb').prepend(html);	        	
        }
    });	
}

function thumb_del(_this){
	_this.parentNode.remove();
}

/**
 * 详情页，附件下载查看列表
 * @param classname
 * @param file_upload
 */
function detail_show_file(classname,file_upload){
	for(var i in file_upload){
		var j = i;
		j = Number(j)
		j = j+1
		html = ""+j+".<img class='' src='img/video.png'/><a href='"+file_upload[i].download+"' class='' style='margin-right:10px'>点击下载附件["+i+"]</a>";		
		$(classname).append(html)
	}
}

/**
 * 获取浏览器路径参数
 * @param sHref
 * @param sArgName
 * @returns {String}
 */
function GetArgsFromHref(sHref, sArgName){
    var args    = sHref.split("?");
    var retval = "";
  
    if(args[0] == sHref) /*参数为空*/
    {
         return retval; /*无需做任何处理*/
    }  
    var str = args[1];
    args = str.split("&");
    for(var i = 0; i < args.length; i ++)
    {
        str = args[i];
        var arg = str.split("=");
        if(arg.length <= 1) continue;
        if(arg[0] == sArgName) retval = arg[1]; 
    }
    return retval;
}